package com.aaa.dao.impl;

import java.util.List;
import java.util.Map;

import com.aaa.dao.CarDAO;
import com.aaa.util.DAOUtil;

public class CarDAOImpl  implements CarDAO {
	
	@Override
	public List<Map<String, Object>> listProductByUid(Integer uid) {
		
		String sql = "select  *  from car  where uid = ?";
		return DAOUtil.executeQuery(sql, uid);
	}
	
	@Override
	public boolean isAddCar(Integer uid, String pid) {
		
		String sql = "select  *  from car where uid = ? and pid = ?";
		
		List<Map<String, Object>> list = DAOUtil.executeQuery(sql, uid , pid);
		
		return list.size() > 0;
	}

	@Override
	public int saveProductToCar(Integer uid, Map<String, Object> args) {
		String sql = "insert  into car  (uid,pid,pname,pimage,price,num) values (?,?,?,?,?,?)";
		return DAOUtil.executeUpdate(sql,uid,args.get("pid"),args.get("pname"),args.get("pimage"),args.get("shopPrice"),args.get("num")  );
	}

	@Override
	public int updateProductNo(Integer uid, Map<String, Object> args) {
		String sql = " update car set  num = num + ?  where uid = ?  and pid = ?";
		return DAOUtil.executeUpdate(sql,  args.get("num")  , uid , args.get("pid")     );
	}

	
}
